import request from "@/utils/request";
import {serverIp} from "../../public/config.js";
const API_BASE_URL = `http://${serverIp}:8081/jdyfy`;

/**
 * 部门API请求
 *
 */

//添加或修改项目
export const addDepartment = (form) =>{
    return request.post(`${API_BASE_URL}/department/save`, form)
        .then(res => {
            if (!res) {
                throw new Error('添加错误');
            }
            return res;
        }).catch(err => {
            throw new Error('请求失败'); // 抛出请求错误
        });
};

//添加企业报名的公告
export const addAnnouDepart = (form) =>{
    return request.post(`${API_BASE_URL}/annouDepart`, form )
        .then(res => {
            return res;
        });
};

//根据企业名获取企业信息
export const getDepartByDepartName = (departmentName) => {
    return request.get(`${API_BASE_URL}/department/getDepartByDepartName`, {params: {departmentName}})
        .then(res => {
            return res.data;
        })
};

//根据企业名集合获取企业信息集合
export const getDepartsByDepartNames  = (departs) =>{
    return request.post(`${API_BASE_URL}/department/getDepartsByDepartNames`,departs).then(res => {
        return res;
    })
}

/**
 * 供应商分页查询
 * @param pageNum
 * @param pageSize
 * @param departmentName
 * @param departmentNumber
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const getSupplerPage = (pageNum, pageSize, departmentName, departmentNumber) =>{
    return request.get(`${API_BASE_URL}/supplerPage`,{
        params: {
            pageNum,
            pageSize,
            departmentName,
            departmentNumber
        }
    }).then(res => {
        return res.data;
    })
};

/**
 *
 * @param form
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const addNoshow = (form) =>{
    return request.post(`${API_BASE_URL}/department/noshow`,form).then(res => {
        return res;
    })
}

//获取供应商总数
export const getSuppler = () =>{
    return request.get(`${API_BASE_URL}/department/getSuppler`,).then(res => {
        return res.data;
    })
}

//通过企业名称获取爽约记录
export const getNoshowByDepartmentPage = (pageNumn, pageSizen,departmentName) =>{
    return request.get(`${API_BASE_URL}/department/noshowByDepartmentPage`,{params: {pageNumn, pageSizen,departmentName}}).then(res => {
        return res.data;
    })
}